package montaltoTests
import montaltoFood._
import montaltoNeds._
import montaltoController._
import montaltoDirections._
import montaltoNeds.Bag
import org.scalatest.Spec
import org.scalatest.matchers.ShouldMatchers
/**
 * Created by IntelliJ IDEA.
 * User: Andrew Montalto
 * Date: Apr 19, 2010
 * Time: 6:27:02 PM
 * To change this template use File | Settings | File Templates.
 */

class TestBag extends Spec with ShouldMatchers{
  describe ("Test Bad,"){
    describe("add mullet to bag"){
      it("should have eleven calorie"){
        var bag:Bag = new Bag()
        var foodFactory:FoodFlyWeightFactory = new FoodFlyWeightFactory()
        bag.add(foodFactory.getFood("meat"))
        bag.add(foodFactory.getFood("meat"))
        var g:GeneticCode = new GeneticCode();
        g.generateRandom()
        bag.currentCalories should be(11)
      }
    }
  }
}
class TestNed extends Spec with ShouldMatchers{
  val g = new GeneticCode()
  g.generateRandom()
  val ned:Ned=new Ned(g)
  describe("Test Neds"){
    describe("generate a first Generation ned"){
      it("Ned should be alive"){
        ned.isAlive should be(true)
      }
    }
    
    it("should have a gender"){
      ned.gender.isInstanceOf[Gender] should be(true)
    }

    it("should have a genetic code 40 chars long"){
      ned.geneticCode.toString.length should be (40)
    }

    it("should add food to bag"){
      val currentCal = ned.bag.currentCalories
      ned.bag.add(new Meat())
      ned.bag.currentCalories > currentCal should be(true)
    }
    it("should eat food"){
      val currentCal = ned.bag.currentCalories
      ned.eat

      ned.bag.currentCalories < currentCal should be (true)

    }
    it("should have a direction"){
      ned.currentDirection.toString should be("North")
    }
    it("should turn 1/8th"){
      ned.turn
      ned.currentDirection.toString should be("NorthEast")
    }
    it("Should have a Command substring"){

      for(i<-1 to 30){
         ned.moveToNextCommand
      }
      println("CMD=" +  ned.currentCommandString)
    }
    it("should die if it doesn't have enough food") {
      while(ned.isAlive){
        ned.eat
      }
      ned.isAlive should be (false)
    }
  }
}

class TestGender extends Spec with ShouldMatchers{
  describe("Test Gender, "){
    describe("make a gender, "){
      it("should be male"){
        val gender:Gender = new Male
        gender.is() should be("male")

      }
      it("should be an instance of gender"){
      //  val gender:Gender =gender.RandomGender();
      //  gender.isInstanceOf[Gender] should be (true)
      }
    }
  }
}
class TestMate extends Spec with ShouldMatchers{
  describe("Test Mating"){
    var n1:Ned = NedBuilder.random
    var n2:Ned = NedBuilder.random
    n1.gender = new Male
    n2.gender = new Female
    val mate = new Mate(n1,n2)
    val n = mate.splitIndex
    it("the split index should be "){
      (n>=0 && n<40) should be(true)
    }
    it("make a baby Ned") {
       mate.tryMating
       if (mate.babyNed != null){
         val n:Ned = mate.babyNed
         n.geneticCode.toString.length should be(40)
       }
    }
  }
}

